package roostersiteconnection;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.DefaultHttpClient;

public class RoosterConnection {
	private URI baseRoosterURI;
	DefaultHttpClient client;
	
	public RoosterConnection(String uri) throws URISyntaxException {
		baseRoosterURI = new URI(uri);
		client = new DefaultHttpClient();
	}
	
	public HttpResponse doGet(String uri) throws URISyntaxException, ClientProtocolException, IOException {
		URI link = new URI(uri);
		link = link.resolve(baseRoosterURI);
		
		HttpGet getMethod = new HttpGet(link);
		return client.execute(getMethod);
	}
	
	public HttpResponse doPost(String uri, HttpEntity entity) throws URISyntaxException, ClientProtocolException, IOException {
		URI link = new URI(uri);
		link = link.resolve(baseRoosterURI);
		
		HttpPost postMethod = new HttpPost(link);
		postMethod.setEntity(entity);
		return client.execute(postMethod);
	}
	
}
